// Fill out your copyright notice in the Description page of Project Settings.


#include "Core/BornPoint.h"

#include "Core/EnemyZDCharacter.h"
#include "Core/Signpost.h"
#include "Kismet/GameplayStatics.h"

// Sets default values
ABornPoint::ABornPoint()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned
void ABornPoint::BeginPlay()
{
	Super::BeginPlay();
}

// Called every frame
void ABornPoint::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	if (EnemyCount >= SpawnEnemyTotal) return;
	
	Timer += DeltaTime;
	if (Timer >= SpawnEnemyInterval)
	{
		Timer -= SpawnEnemyInterval;
		EnemyCount++;
		
		FTransform Transform = FTransform(GetActorLocation());
		Transform.SetRotation(GetActorRotation().Quaternion());
		AEnemyZDCharacter* Enemy = Cast<AEnemyZDCharacter>(UGameplayStatics::BeginDeferredActorSpawnFromClass(GetWorld(), EnemyClass, Transform, ESpawnActorCollisionHandlingMethod::AlwaysSpawn));
		if (Enemy)
		{
				Enemy->SetNextLocation(NextPoint->GetActorLocation());
		}
		UGameplayStatics::FinishSpawningActor(Enemy, Transform);
	}
}

